<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="example">
<tode>

    <tode-title slot="tode-title" :title="title"></tode-title>
    <tode-items slot="tode-items" v-for="(item,index) in todeItems"
                :item="item" v-bind:index="index" v-on:remove="removeItems(index)"></tode-items>
</tode>
</div>

<!--导入Vue.js-->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

<script>
    //slot: 插槽
    Vue.component("tode",{
       template: '<div>\
                       <slot name="tode-title"></slot>\
                       <ul>\
                            <slot name="tode-items"></slot>\
                       </ul>\
                  </div>'
       // '<div>' +
       // '<slot></slot>' +
       //     '<ul>'+
       //     '<slot></slot>' +
       //     '</ul>'+
       // '</div>'
    });
    Vue.component("tode-title",{
        props: ['title'],
       template: '<div>{{title}}</div>'
    });
    Vue.component("tode-items",{
        props: ['item','index'],
        //只能绑定当前组件的方法
        template: '<li>{{index}}--{{item}}<button @click="remove">删除</button></li>',
        methods: {
            remove: function (index){
                this.$emit('remove',index)
            }
        }
    });

    var vm = new Vue({
        el: '#example',
        data: {
            title: "列表",
            todeItems: ['11','22','33']
        },
        methods: {
            removeItems: function (index) {
                console.log("删除了"+this.todeItems[index]+"OK");
                this.todeItems.splice(index,1);
            }
        }
    });
</script>

</body>
</html>